import 'package:cached_network_image/cached_network_image.dart';
import 'package:du_application/provide/CollectProvider.dart';
import 'package:du_application/routes/application.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:provide/provide.dart';

class CollectPage extends StatelessWidget {
  const CollectPage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Provide.value<CollectProvider>(context).getCollect(context);
      ScrollController scrollController = ScrollController();
        final _loadingContainer = Container(
      width: ScreenUtil().setHeight(1080),
      height: ScreenUtil().setHeight(1920),
      constraints: BoxConstraints.expand(),
      color: Colors.black,
      child: Center(
        child: Opacity(
          opacity: 0.9,
          child: SpinKitWave(
            color: Colors.white,
            size: 50.0,
          ),
        ),
      ));
    return Provide<CollectProvider>(
      builder: (context,child,index){
   return index==null||index.collectModel==null?_loadingContainer:Scaffold(
      appBar:AppBar(
        title: Text("我的收藏"),
   
      ),
           body:Container(
             child: ListView(
            controller: scrollController,
           children:index.collectModel.data.list.map((order){
         return 
       InkWell(
         
   onTap: (){
     Application.router.navigateTo(context, "/goods?id=${order.valueId}");
   },
   onLongPress: (){
  showModalBottomSheet(context: context,builder:(context){
    return Container(
    child:Column(
      children:[
      InkWell(
        onTap: () async {
      bool result=   await index.delCollect(context, order.valueId);
      if(result){
           Navigator.pop(context);
      }
        },
        child: Container(
          margin: EdgeInsets.symmetric(horizontal:ScreenUtil().setWidth(20),vertical:ScreenUtil().setWidth(10) ),
          padding: EdgeInsets.symmetric(vertical:ScreenUtil().setWidth(40)),
          alignment: Alignment.center,
         width: ScreenUtil().setWidth(1080),
            child: Text("删除",style: TextStyle(color:Colors.white),),
          decoration: BoxDecoration(
            color:Colors.cyan[400],
          ),
        )
      ),
      InkWell(
        onTap: (){
       Navigator.pop(context);
        },
        child: Container(
          margin: EdgeInsets.symmetric(horizontal:ScreenUtil().setWidth(20),vertical:ScreenUtil().setWidth(10) ),
          padding: EdgeInsets.symmetric(vertical:ScreenUtil().setWidth(40)),
          alignment: Alignment.center,
         width: ScreenUtil().setWidth(1080),
            child: Text("取消",style: TextStyle(color:Colors.white),),
          decoration: BoxDecoration(
            color:Colors.cyan[400],
          ),
        )
      ),
   
        
      ]
    ),
    );
  } );
   },
         child: Card(
          child:
            Container(
             padding: EdgeInsets.symmetric(vertical: ScreenUtil().setWidth(15)),
              child: Column(
             crossAxisAlignment: CrossAxisAlignment.start,
             mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
         
            Row(
              children: <Widget>[
           Container(
          width: ScreenUtil().setWidth(200),
          height: ScreenUtil().setHeight(200),
          padding: EdgeInsets.all(ScreenUtil().setSp(10)),
          child: CachedNetworkImage(
            height: ScreenUtil().setWidth(200),
            width: ScreenUtil().setWidth(200),
            imageUrl: order.picUrl,
            fit: BoxFit.fitWidth,
            placeholder: (context, url) =>
                Image.asset('assets/loading.jpg'),
          ),
                ),
                Stack(
          children: <Widget>[ 
            Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(
              width: ScreenUtil().setWidth(850),
              child: Text(order.name,
                  maxLines: 2),
            ),
           //  Container(
           //      margin: EdgeInsets.only(
           //          top: ScreenUtil().setSp(10),
           //          bottom: ScreenUtil().setSp(10)),
           //      height: ScreenUtil().setHeight(50),
           //      child: Text("order.goods.specifications")),
              Row(
                children: <Widget>[
                    Text("￥",style: TextStyle(fontWeight: FontWeight.bold,fontSize: ScreenUtil().setSp(20)),),
                    Text(order.retailPrice.toString(),style: TextStyle(fontWeight: FontWeight.bold,fontSize: ScreenUtil().setSp(30))),
                  ],
               ) ],
            )
          ],
                )
              ],
            )
              ],
              )
            ),
             )
       );

    }).toList()
             ),
           ),
    );
      },
    ); 
  }
}